package cn.zzf.algs.note.exercise.fundamental;

import edu.princeton.cs.algs4.StdDraw;
import edu.princeton.cs.algs4.StdOut;
import edu.princeton.cs.algs4.StdRandom;

/**
 * @author GaoFeng
 * @date 2019/11/25 19:15
 */
public class Ex1_1_32 {

    public static void main(String[] args) {
         // draw();
        drawTest();
    }


    public static void draw() {

        // 直方图。假设标准输入流中含有一系列double 值。
        // 编写一段程序，从命令行接受一个整数N 和两个double 值l 和r。将(l，r) 分为N 段并使用StdDraw 画出输入流中的值落入每段的数量的直方图。
        int n = 32;
        double l = 0.0;
        double r = 100.0;
        StdDraw.setCanvasSize(1000, 1000);

        double[] nums = new double[n];

        double increment = (r - l) / n;

        for (int i = 0;i < n;i++) {
            double value = (l + increment * (i + 1)) / r;
            double x = 1.0 * i / n;
            double y = value / 2.0;
            double rw = 0.5 / n;
            double rh = value / 2.0;
            StdDraw.filledRectangle(x, y, rw, rh);
        }


    }

    public static void drawTest() {

        StdDraw.setCanvasSize(1000, 1000);

        int n = 100;
        double[] a = new double[n];

        for(int i = 0;i < n; i++) {
            a[i] = StdRandom.uniform();
        }

        for (int i = 0; i < n; i++) {
            double x = 1.0 * i / n;
            double y = a[i] / 2.0;
            double rw = 0.5/n;
            double rh = a[i]/2.0;
            StdOut.println(x + "-" + y + "-" + rw + "-" + rh);
            StdDraw.filledRectangle(x, y, rw, rh);
        }

        // StdDraw.

    }

}
